class Solution {
public:
    int subarraySum(vector<int>& nums,int k) {
        unordered_map<int,int> count;
        count[0]=1;
        
        int prefixSum=0;
        int result=0;
        
        for (int num : nums) {
            prefixSum += num;
            if (count.find(prefixSum-k) != count.end()) {
                result += count[prefixSum-k];
            }
            count[prefixSum]++;
        }
        return result;
    }
};
